package com.whp02.annotation.bean;

import com.whp.listener_event.TestEvent;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @author wanghp
 * @version 1.0
 * @date 2020/9/24 10:53
 */
@Component
@Import(M.class)
public class User0924 implements ApplicationContextAware {

	@Autowired
	private M m;

	@Bean
	public Executor getExecutor() {
		return Executors.newSingleThreadExecutor();
	}

	@Component
	class TestListener03 implements ApplicationListener<ApplicationEvent>, LifecycleProcessor {
		@Override
		public void onApplicationEvent(ApplicationEvent event) {
			System.out.println(event);
			System.out.println("-------------------进入自定义Event03");
			if (event instanceof TestEvent) {
				((TestEvent) event).print();
			}

		}

		@Override
		public void onRefresh() {
			System.out.println("--------------进入自定义LifecycleProcessor的onRefresh方法");
		}

		@Override
		public void onClose() {
			System.out.println("--------------进入自定义LifecycleProcessor的onClose方法");
		}

		@Override
		public void start() {
			System.out.println("--------------进入自定义LifecycleProcessor的start方法");
		}

		@Override
		public void stop() {
			System.out.println("--------------进入自定义LifecycleProcessor的stop方法");
		}

		@Override
		public boolean isRunning() {
			return false;
		}
	}


//	public User0924() {
//		System.out.println("instance user0924 User0924");
//	}

//	@Autowired
//	public User0924(M m) {
//		System.out.println("instance user0924 User0924 M:"+m);
//
//	}

	private String userName;
	private static int age;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public static int getAge() {
		return age;
	}

	public static void setAge(int age) {
		User0924.age = age;
	}

	private void test() {

	}

	public void printM() {
		System.out.println("输出m " + m);
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

	}
}
